import os

from eml_bill_html_data import parse_eml, write_eml_to_html, write_html_to_txt, read_html_table


def eml_to_txt(eml_file, output_tmp_files=False):
    if output_tmp_files:
        write_eml_to_html(eml_file)
        write_html_to_txt(eml_file.replace('.eml', '.html'))
        print(eml_file.replace('.eml', ' 处理完成'))
        return

    read_html_table(parse_eml(eml_file))


if __name__ == '__main__':
    for file_addr in os.listdir('.'):
        if file_addr.endswith('.eml'):
            eml_to_txt(file_addr)
